package cn.weiwei.WHadoop.hdfs.url;

import org.apache.hadoop.fs.FsUrlStreamHandlerFactory;
import org.apache.hadoop.io.IOUtils;

import java.io.IOException;
import java.io.InputStream;
import java.net.URL;

/**
 * @author WangWeiwei
 * @version 1.0
 * @sine 17-2-6
 *
 * 通过URLStreamHandler实例以标准输出方式显示Hadoop文件系统中的文件
 */
public class URLCat {
    static {
        URL.setURLStreamHandlerFactory(new FsUrlStreamHandlerFactory());
    }

    public void catFile(String[] args) throws IOException {
        InputStream inputStream = null;
        try {
            inputStream = new URL(args[0]).openStream();
            IOUtils.copyBytes(inputStream,System.out,4096,false);
        }finally {
            IOUtils.closeStream(inputStream);
        }
    }
}
